package pl.maciejziarko.mshare.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;
import pl.maciejziarko.mshare.domain.Account;
import pl.maciejziarko.mshare.domain.Role;
import pl.maciejziarko.mshare.persistence.RoleMapper;
import pl.maciejziarko.mshare.service.exception.RoleAlreadyGranted;
import pl.maciejziarko.mshare.service.exception.RoleNotGranted;
import pl.maciejziarko.mshare.service.exception.RoleServiceException;

import java.util.List;

/**
 * @author Maciej Ziarko
 */
@Component
public class MShareRoleService implements RoleService {

    private static final Logger LOG = LoggerFactory.getLogger(MShareRoleService.class);
    
    private RoleMapper roleMapper;

    @Autowired
    public MShareRoleService(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Override
    public List<Role> getRoles(Account account) throws RoleServiceException {
        try {
            return roleMapper.selectRoles(account);
        } catch (DataAccessException e) {
            throw new RoleServiceException();
        }
    }

    @Override
    public void addRole(Account account, Role role) throws RoleAlreadyGranted, RoleServiceException {
        //TODO
        throw new AssertionError("Not implemented yet.");
    }

    @Override
    public void removeRole(Account account, Role role) throws RoleNotGranted, RoleServiceException {
        //TODO
        throw new AssertionError("Not implemented yet.");
    }
}
